import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;


public class PokerCalcEngine implements ActionListener, FocusListener{
	
	PokerCalc parent;
		PokerCalcEngine (PokerCalc parent){
		this.parent = parent;
	}
	
		
	@Override
	public void focusGained(FocusEvent a) {
		Object obr = a.getSource();
		if (obr == parent.topTextPanel){
		parent.topTextPanel.setText("");
		}else if(obr == parent.fieldhm1){
		parent.fieldhm1.setText("");
		}else if(obr == parent.fieldhm5){
		parent.fieldhm5.setText("");
		}else if(obr == parent.fieldhm25){
		parent.fieldhm25.setText("");
		}else if(obr == parent.fieldhm50){
		parent.fieldhm50.setText("");
		}else if(obr == parent.fieldhm100){
		parent.fieldhm100.setText("");
		}else if(obr == parent.fieldnum1){
		parent.fieldnum1.setText("");
		}else if(obr == parent.fieldnum5){
		parent.fieldnum5.setText("");
		}else if(obr == parent.fieldnum25){
		parent.fieldnum25.setText("");
		}else if(obr == parent.fieldnum50){
		parent.fieldnum50.setText("");
		}else if(obr == parent.fieldnum100){
		parent.fieldnum100.setText("");
		}
	}	
	
	
	public void keyReleased(KeyEvent e) {
        
    }
	
	@Override
	public void actionPerformed(ActionEvent e) {
		
		Object obr = e.getSource();
		double	nm1 = Double.parseDouble(parent.fieldnum1.getText());
		double	hm1 = Double.parseDouble(parent.fieldhm1.getText());
		double result1 = nm1 * hm1;
		
		double	nm5 = Double.parseDouble(parent.fieldnum5.getText());
		double	hm5 = Double.parseDouble(parent.fieldhm5.getText());
		double result5 = nm5 * hm5;
		
		double	nm25 = Double.parseDouble(parent.fieldnum25.getText());
		double	hm25 = Double.parseDouble(parent.fieldhm25.getText());
		double result25 = nm25 * hm25;
		
		double	nm50 = Double.parseDouble(parent.fieldnum50.getText());
		double	hm50 = Double.parseDouble(parent.fieldhm50.getText());
		double result50 = nm50* hm50;
		
		double	nm100 = Double.parseDouble(parent.fieldnum100.getText());
		double	hm100 = Double.parseDouble(parent.fieldhm100.getText());
		double result100 = nm100* hm100;
		double resultsumm = result1 + result5 + result25 + result50 + result100;
				
		if (obr == parent.button1) {
			parent.topTextPanel.setText(""+result1);
			}else if(obr == parent.button5) {
			parent.topTextPanel.setText(""+result5);
			}else if(obr == parent.button25) {
			parent.topTextPanel.setText(""+result25);
			}else if(obr == parent.button50) {
			parent.topTextPanel.setText(""+result50);
			}else if(obr == parent.button100) {
			parent.topTextPanel.setText(""+result100);
			}else if(obr == parent.buttonsumm) {
			parent.topTextPanel.setText(""+resultsumm);	
			}
	
		}



	@Override
	public void focusLost(FocusEvent arg0) {
		// TODO Auto-generated method stub
		
	}
}
